package gogs_hook

import "jihulab.com/linksaas/proto-gen-go/events/events_gogs"

type PullRequestHook struct {
	Action      string       `json:"action"`
	Index       int64        `json:"number"`
	PullRequest *PullRequest `json:"pull_request"`
	Changes     *Changes     `json:"changes,omitempty"`
	Repository  *Repository  `json:"repository"`
	Sender      *User        `json:"sender"`
}

func (item *PullRequestHook) ToProtoBuf() *events_gogs.PullRequestEvent {
	ret := &events_gogs.PullRequestEvent{
		Action:      item.Action,
		Index:       item.Index,
		PullRequest: []*events_gogs.PullRequest{},
		Changes:     []*events_gogs.Changes{},
		Repository:  []*events_gogs.Repository{},
		Sender:      []*events_gogs.User{},
	}
	if item.PullRequest != nil {
		ret.PullRequest = append(ret.PullRequest, item.PullRequest.ToProtoBuf())
	}
	if item.Changes != nil {
		ret.Changes = append(ret.Changes, item.Changes.ToProtoBuf())
	}
	if item.Repository != nil {
		ret.Repository = append(ret.Repository, item.Repository.ToProtoBuf())
	}
	if item.Sender != nil {
		ret.Sender = append(ret.Sender, item.Sender.ToProtoBuf())
	}
	return ret
}
